T
Entity type
IdeaBlade DevForce 2010 Help Reference
AddFilter<T>(Func<IQueryable<T>,IQueryable<T>>,Boolean) Method
See Also  Example Send Feedback
IdeaBlade.EntityModel Assembly > IdeaBlade.EntityModel Namespace > EntityQueryFilterCollection Class > AddFilter Method : AddFilter<T>(Func<IQueryable<T>,IQueryable<T>>,Boolean) Method



transformFunc
A Func that takes and returns an IQueryable{T}
canReplaceIfAlreadyExists
Add a filter for an entity type to the collection.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub AddFilter(Of T As Class)( _
   ByVal transformFunc As Func(Of IQueryable(Of T),IQueryable(Of T)), _
   Optional ByVal canReplaceIfAlreadyExists As Boolean _
) 
Visual Basic (Usage)Copy Code
Dim instance As EntityQueryFilterCollection
Dim transformFunc As Func(Of IQueryable(Of T),IQueryable(Of T))
Dim canReplaceIfAlreadyExists As Boolean
 
instance.AddFilter(Of T)(transformFunc, canReplaceIfAlreadyExists)
C# 
public void AddFilter<T>( 
   Func<IQueryable<T>,IQueryable<T>> transformFunc,
   bool canReplaceIfAlreadyExists
)
where T: class
C++/CLI 
public:
void AddFiltergeneric<typename T>
( 
   Func<IQueryable<T^>^,IQueryable<T^>^>^ transformFunc,
   bool canReplaceIfAlreadyExists
) 
where T: ref class

Parameters

transformFunc
A Func that takes and returns an IQueryable{T}
canReplaceIfAlreadyExists

Type Parameters

T
Entity type

Exceptions

ExceptionDescription
System.ArgumentExceptionThrown if a filter for the entity type is already in the collection and the canReplaceIfAlreadyExists paremter is set to false

Example

C#Copy Code
public void FilteringSample() {
  // Query for all customers.  A filter will be applied prior to execution.
  var mgr = new DomainModelEntityManager();
  var list = mgr.Customers.ToList();
}

// Server-side implementation of EntityServerQueryInterceptor
public class EntityServerQueryManager : EntityServerQueryInterceptor {

  protected override bool FilterQuery()
    // Add filters
    QueryFilters.AddFilter<Customer>(q => q.Where(c => c.Country == "USA"));
    QueryFilters.AddFilter<Employee>(q => q.Where(e => e.Country == "USA"));
    return true;
	}
}

Remarks

The transformFunc, although it looks intimidating, is really a simple Where predicate which you're already familiar with when using query expression syntax. See the example for more information.

Requirements

Target Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family

See Also

© 2013 All Rights Reserved.